﻿using System;
using System.Collections;
using System.Collections.Generic;

using Wsitech.Model;
using Wsitech.Persistence.Interface;

namespace Wsitech.Persistence.Dao
{
    /// <summary>
    /// 功能：     SiteMapInfo业务接口的实现
    /// 作者：     LI
    /// 日期：     5/16/2012
    /// 修改日期： 
    /// 修改人：
    /// 修改内容：
    /// </summary>
    public class SiteMapInfoSqlMapDao : BaseSqlMapDao, ISiteMapInfoDao
    {
        private SiteMapInfoSqlMapDao()
        {
            //
            // TODO: 此处添加SiteMapInfoSqlMapDao的构造函数
            //
        }

        #region 懒汉单例模式

        private static SiteMapInfoSqlMapDao instance = null;
        private static object syncRoot = new object();
        public static ISiteMapInfoDao Instance
        {
            get
            {
                if (instance == null)
                {
                    lock (syncRoot)
                    {
                        if (instance == null)
                        {
                            instance = new SiteMapInfoSqlMapDao();
                        }
                    }
                }
                return instance;
            }
        }

        #endregion

        #region	基本功能 ，不可修改

        /// <summary>
        /// 得到明细
        /// </summary>
        /// <param name="SitemapId"></param>
        /// <returns></returns>
        public SiteMapInfo GetDetail(System.String sitemapid)
        {
            try
            {
                return ExecuteQueryForObject<SiteMapInfo>("SelectSiteMapInfo", sitemapid) as SiteMapInfo;
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 得到列表
        /// </summary>
        /// <returns></returns>
        public System.Collections.Generic.IList<SiteMapInfo> GetList()
        {
            try
            {
                return ExecuteQueryForList<SiteMapInfo>("SelectSiteMapInfo", null);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 通过不同参数得到列表
        /// </summary>
        /// <param name="objParameters"></param>
        /// <returns></returns>
        public System.Collections.Generic.IList<SiteMapInfo> GetListByParams(object objParameters)
        {
            try
            {
                return ExecuteQueryForList<SiteMapInfo>("SelectSiteMapInfoByParams", objParameters);
            }
            catch
            {
                throw;
            }
        }



        /// <summary>
        /// 新建
        /// </summary>
        /// <param name="sitemapinfo"></param>
        /// <returns></returns>
        public object Add(SiteMapInfo sitemapinfo)
        {
            //int id = GetId("SiteMapInfo");
            //sitemapinfo.SitemapId = id;

            try
            {
                return ExecuteInsert("InsertSiteMapInfo", sitemapinfo);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="sitemapinfo"></param>
        /// <returns></returns>
        public int Update(SiteMapInfo sitemapinfo)
        {
            try
            {
                return ExecuteUpdate("UpdateSiteMapInfo", sitemapinfo);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="SitemapId"></param>
        /// <returns></returns>
        public int Delete(System.String sitemapid)
        {
            try
            {
                return ExecuteDelete("DeleteSiteMapInfo", sitemapid);
            }
            catch
            {
                throw;
            }
        }
        #endregion

        #region 扩展功能

        #region 查询父菜单下的最大索引
        /// <summary>
        /// 查询父菜单下的最大索引
        /// </summary>
        /// <param name="parentId"></param>
        /// <returns></returns>
        public int GetMaxIndexByParentId(string parentId)
        {
            try
            {
                return Convert.ToInt32(ExecuteQueryForObject("SelectMaxSiteMapIndexByParentId", parentId) ?? 0);
            }
            catch (Exception)
            {

                throw;
            }
        }

        public IList<SiteMapInfo> GetBackendParentList()
        {
            return ExecuteQueryForList<SiteMapInfo>("GetBackendParentList", null);
        }

        #endregion

        #endregion
    }
}
